package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.role.RoleIdData;
import com.jinmdz.fmis.api.admin.model.role.RoleLoadData;
import com.jinmdz.fmis.api.admin.model.role.RoleSaveData;
import com.jinmdz.fmis.api.admin.service.RoleService;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.admin.model.role.RoleListData;
import com.jinmdz.fmis.dao.admin.model.role.RoleListItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 角色维护信息相关接口
 *
 * @author LiCongLu
 * @date 2020-03-18 13:20
 */
@Api(description = "角色维护信息相关接口")
@RestController()
@RequestMapping("/admin/role")
public class RoleController extends BaseController {

    @Resource
    private RoleService roleService;

    /**
     * 加载角色信息
     *
     * @param data 查询条件
     * @return
     * @author LiCongLu
     * @date 2020-03-18 13:20
     */
    @ApiOperation(value = "根据查询条件加载表【business_system_role】中保存的角色数据", notes = "根据查询条件加载表【business_system_role】中保存的角色数据")
    @PostMapping("/load-role-list-with-business-system-id")
    public BaseResult<ArrayList<RoleListItem>> loadRoleListWithBusinessSystemId(@RequestBody RoleListData data) {
        return resultHandler(data, userItem -> roleService.loadRoleListWithBusinessSystemId(data));
    }

    /**
     * 加载角色信息
     *
     * @param data 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-18 13:20
     */
    @ApiOperation(value = "根据【business_system_role】表中id加载角色信息", notes = "根据ID加载角色信息")
    @PostMapping("/load-role-with-id")
    public BaseResult<RoleLoadData> loadRoleWithId(@RequestBody RoleIdData data) {
        return resultHandler(data, userItem -> roleService.loadRoleWithId(data));
    }

    /**
     * 保存角色信息到business_system_role表中
     *
     * @param data 请求数据
     * @return
     * @author LiCongLu
     * @date 2020-03-18 13:20
     */
    @ApiOperation(value = "保存角色信息到【business_system_role】表中", notes = "保存角色信息到【business_system_role】表中")
    @PostMapping("/save-role")
    public BaseResult saveRole(@RequestBody RoleSaveData data) {
        return resultHandler(data, userItem -> roleService.saveRole(userItem, data));
    }

    /**
     * 从business_system_role表中删除指定id的角色信息记录
     *
     * @param data 主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-03-18 13:20
     */
    @ApiOperation(value = "从business_system_role表中删除指定id的角色信息记录", notes = "从business_system_role表中删除指定id的角色信息")
    @PostMapping("/delete-role-with-id")
    public BaseResult deleteRoleWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> roleService.deleteRoleWithId(userItem, data));
    }
}
